package cn.school.demo

import android.os.Environment
import cn.school.demo.util.SensitivewordFilter
import org.jsoup.Jsoup
import org.junit.Test

/**
 * Example local unit test, which will execute on the development machine (host).
 *
 * See [testing documentation](http://d.android.com/tools/testing).
 */
class ExampleUnitTest {
    @Test
    fun addition_isCorrect() {
        //assertEquals(4, 2 + 2)
        val classLoader = Thread.currentThread().contextClassLoader
        val u = classLoader.getResource("sensitiveword.text")
        val uu = javaClass.classLoader.getResource(".").path
        println(uu)
    }

    @Test
    fun webTest() {
        val document = Jsoup.connect("https://www.sdtbu.edu.cn/index/tzgg.htm").get()
        val elements = document.select("a.c75870").eachText()
        elements.forEach {
            println(it)
        }
        println(elements.size)
    }

    @Test
    fun webTest2() {
        /*val document = Jsoup.connect("https://www.sdtbu.edu.cn/info/1045/28006.htm").get()
        val elements = document.select("div.fr").html()
        println(elements)*/
        val document = Jsoup.parse(
            "<section data-role=\"outer\" label=\"Powered by 135editor.com\" style=\"\"><section class=\"_135editor\" data-role=\"paragraph\"><p style=\"text-align:center;vertical-align:inherit;text-indent: 0px;\"><strong><span style=\"letter-spacing: 0px; font-size: 16px; font-family: &quot;Times New Roman&quot;;\">1.3.1 <span style=\"font-family: 宋体;\">封面及固定页面要求（见范文）</span></span></strong></p><p style=\"vertical-align:inherit;margin-bottom:0;margin-left:0;text-indent:40px;line-height:150%\"><strong><span style=\"font-size: 16px; font-family: &quot;Times New Roman&quot;;\"><span style=\"font-family: 宋体;\">论文题目</span></span></strong><span style=\"font-size: 16px; font-family: &quot;Times New Roman&quot;;\"><span style=\"font-family: 宋体;\">：应是整个论文总体内容的体现，要引人注目，力求简短，严格控制在</span>25<span style=\"font-family: 宋体;\">字以内。</span></span></p><p style=\"vertical-align:inherit;margin-left:14px;text-indent:24px;line-height:150%\"><strong><span style=\"font-size: 16px; font-family: &quot;Times New Roman&quot;;\"><span style=\"font-family: 宋体;\">中文摘要</span></span></strong><span style=\"font-size: 16px; font-family: &quot;Times New Roman&quot;;\"><span style=\"font-family: 宋体;\">：应将论文的内容要点简短明了地表达出来，约</span>300</span><span style=\"font-size: 16px; font-family: 宋体;\"><span style=\"font-family: 宋体;\">－</span></span><span style=\"font-size: 16px; font-family: &quot;Times New Roman&quot;;\">500<span style=\"font-family: 宋体;\">字左右。内容应包括研究目的、研究方法、成果和结论。要突出本论文的创新点，语言力求精炼。为了便于文献检索，在本页下方另起一行注明论文的关键词（</span><span style=\"font-family: &quot;Times New Roman&quot;;\">3</span></span><span style=\"font-size: 16px; font-family: 宋体;\"><span style=\"font-family: 宋体;\">－</span></span><span style=\"font-size: 16px; font-family: &quot;Times New Roman&quot;;\">7<span style=\"font-family: 宋体;\">个）。</span></span><strong><span style=\"font-size: 16px; font-family: &quot;Times New Roman&quot;;\"><span style=\"font-family: 宋体;\">（见范文）</span></span></strong></p><p style=\"vertical-align:inherit;margin-left:4px;text-indent:32px;line-height:150%\"><strong><span style=\"font-size: 16px; font-family: &quot;Times New Roman&quot;;\"><span style=\"font-family: 宋体;\">英文摘要</span>:</span></strong><span style=\"font-size: 16px; font-family: &quot;Times New Roman&quot;;\">&nbsp;<span style=\"font-family: 宋体;\">内容应与中文摘要相同。</span></span><strong><span style=\"font-size: 16px; font-family: &quot;Times New Roman&quot;;\"><span style=\"font-family: 宋体;\">（见范文）</span></span></strong></p><p style=\"vertical-align:inherit;\"><br/></p></section><section class=\"_135editor\" data-id=\"image-77213\"><p style=\"text-align:center;vertical-align:inherit;\"><img src=\"https://images.unsplash.com/photo-1526755393771-bf2e591f33a0?auto=format&fit=crop&w=500&q=80&cs=tinysrgb\" referrerpolicy=\"no-referrer\" data-model=\"Image\" style=\"box-sizing:border-box;vertical-align: inherit; width: 282px; height: 282px;\" alt=\"\" data-ratio=\"1\" data-w=\"500\" width=\"282\" height=\"282\"/></p></section><section class=\"_135editor\" data-role=\"paragraph\"><p style=\"vertical-align:inherit;\"><br/></p></section></section>"
        )
        val elements = document.getElementsByTag("img")
        val src = elements.first().attr("src")
        println(src)
    }

//    @Test
//    fun dateTimeTest() {
//        val a = LocalDateTime.now()
//        var b = LocalDateTime.of(LocalDate.now(), LocalTime.of(11, 30, 0))
//        println(a)
//        println(b)
//        val c = ChronoUnit.SECONDS.between(a, b)
//        println(LocalTime.ofSecondOfDay(c))
//    }
    @Test
    fun SensitivewordTest(){
    val filter = SensitivewordFilter(null)
    println("敏感词的数量：" + filter.sensitiveWordMap.size)
    val string = ("太多的伤感情怀也许只局限于饲养基地 荧幕中的情节，主人公尝试着去用某种方式渐渐的很潇洒地释自杀指南怀那些自己经历的伤感。"
            + "然后法轮功 我们的扮演的角色就是跟随着主人公的喜红客联盟 怒哀乐而过于牵强的把自己的情感也附加于银幕情节中，然后感动就流泪，"
            + "难过就躺在某一个人的怀里尽情的阐述心扉或者手机卡复制器一个人一杯红酒一部电影在夜三级片 深人静的晚上，关上电话静静的发呆着。许运鸿手淫zhuanfalu")
    println("待检测语句字数：" + string.length)
    val beginTime = System.currentTimeMillis()
    val set = filter.getSensitiveWord(string, 1)
    val endTime = System.currentTimeMillis()
    println("语句中包含敏感词的个数为：" + set.size + "。包含：" + set)
    println("总共消耗时间为：" + (endTime - beginTime))
    }
}